import { getMenuByRouter,getTagNavListFromLocalstorage,getBreadCrumbList,getHomeRoute,setTagNavListInLocalstorage} from '../../libs/util';
import router from '../../router/router';

export default {
    state: {
        breadCrumbList: [],
        tagNavList: [],
        userName:'林泽锋',
        homeRoute: getHomeRoute(router),
        menuList:'',
        local: ''
    },
    getters: {
        menuList:(state, getters, rootState) => getMenuByRouter(router, rootState.user.access)
    },
    mutations: {
        setBreadCrumb (state, routeMetched) {
            console.log("----------------"+JSON.stringify(state.homeRoute));
            console.log(JSON.stringify(getBreadCrumbList(routeMetched, state.homeRoute)));
            state.breadCrumbList = getBreadCrumbList(routeMetched, state.homeRoute)
            console.log(JSON.stringify(state.breadCrumbList));
        },
        setTagNavList (state, list) {
            if (list) {
                state.tagNavList = [...list]
                setTagNavListInLocalstorage([...list])
            } else state.tagNavList = getTagNavListFromLocalstorage()
        },
        addTag (state, item, type = 'unshift') {
            if (state.tagNavList.findIndex(tag => tag.name === item.name) < 0) {
                if (type === 'push') state.tagNavList.push(item)
                else state.tagNavList.unshift(item)
                setTagNavListInLocalstorage([...state.tagNavList])
            }
        },
        setLocal (state, lang) {
            state.local = lang
        }
    }
};